package com.dahaiwuliang.code.dao;

import com.dahaiwuliang.code.pojo.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface MessageDao extends JpaRepository<Message,Integer>  ,JpaSpecificationExecutor<Message>{

    @Query(value = "select count(*) from message where is_see=false and user_id=?1",nativeQuery = true)
    Integer getCountByUserId(Integer userId);


    @Query(value = "update message set is_see=true where user_id=?1",nativeQuery = true)
    @Modifying
    void uodateState(Integer userId);
}
